package com.cheejee.goodscenter.controller;

import static com.cheejee.goodscenter.util.ResponseCode.OK;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cheejee.goodscenter.module.entity.Brand;
import com.cheejee.goodscenter.module.entity.BrandPropertiesGroup;
import com.cheejee.goodscenter.module.response.BaseReponse;
import com.cheejee.goodscenter.module.response.PageReponse;
import com.cheejee.goodscenter.module.vo.BrandVo;
import com.cheejee.goodscenter.service.BrandPropertiesTemplateService;
import com.cheejee.goodscenter.service.BrandService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * @author CARRY
 * @Date 2020年10月22日下午4:46:56
 */
@RestController
@RequestMapping("/brand")
@Api(tags = "品牌")
public class BrandController {

	@Resource
	private BrandService brandService;
	
	@GetMapping("/")
	@ApiOperation("查询所有品牌")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "pageSize", value = "每页内容数", defaultValue = "0", dataType = "int"),
		@ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "0", dataType = "int") })
	public Object getAllBrand(int pageNum, int pageSize) {
		
		return new PageReponse(OK, "查询完成", brandService.queryBrand(null, null, pageNum, pageSize));
	}
	
	@GetMapping("/initial")
	@ApiOperation(value = "按首字母查询品牌", notes = "传入other查询其他开头的品牌")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "initial", value = "首字母", dataType = "string"),
		@ApiImplicitParam(name = "pageSize", value = "每页内容数", defaultValue = "0", dataType = "int"),
		@ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "0", dataType = "int") })
	public Object getBrandByInitial(String initial , int pageNum, int pageSize) {
		
		return new PageReponse(OK, "查询完成", brandService.queryBrand(null, initial, pageNum, pageSize));
	}
	
	@GetMapping("/{id}")
	@ApiOperation("按品牌ID查询品牌")
	public Object getBrandById(@PathVariable Integer id) {
		
		return BaseReponse.ok("查询成功", brandService.queryBrandById(id));
	}
	
	@PutMapping("/")
	@ApiOperation("新增品牌")
	public Object addBrand(@RequestBody BrandVo brand){
		Brand b = BrandVo.convert(brand);
		brandService.addBrand(b);
		
		return BaseReponse.ok("新增完成", brandService.queryBrandById(b.getId()));
	}
	
	@PutMapping("/{id}")
	@ApiOperation("修改品牌信息")
	public Object changeBrand(@PathVariable Integer id, @RequestBody BrandVo brand) {
		brandService.changeBrand(BrandVo.convert(id, brand));
		
		return BaseReponse.ok("修改完成", brandService.queryBrandById(id));
	}
	
	@DeleteMapping("/{id}")
	@ApiOperation(value = "删除品牌", notes = "可以同时删除多个品牌，传入品牌ID数组")
	public Object deleteBrand(@PathVariable Integer[] id) {
		brandService.deleteBrand(id);
		
		return BaseReponse.ok("删除完成");
	}
}
